package idiet.dao.hibernate;

import idiet.bean.MealFamily;

import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository("mealFamilyDao")
public class MealFamilyDao extends BaseDao {
	public MealFamily getMealFamilyById(int mealFamilyId){
		return (MealFamily) this.sessionFactory
				.getCurrentSession()
				.createCriteria(MealFamily.class)
				.add(Restrictions.eq("id", mealFamilyId))
				.uniqueResult();
	}
	@SuppressWarnings("unchecked")
	public List<MealFamily> getMealFamilysByMealFamilyName(String name){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(MealFamily.class)
				.add(Restrictions.like("name",name))
				.list();
	}
	@SuppressWarnings("unchecked")
	public List<MealFamily> getMealFamilys(){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(MealFamily.class)
				.list();
	}
	public void createMealFamily(MealFamily mealFamily){
		this.sessionFactory
		.getCurrentSession()
		.save(mealFamily);
	}
	public void updateMealFamily(MealFamily mealFamily){
		this.sessionFactory
		.getCurrentSession()
		.update(mealFamily);
	}
	public void deleteMealFamily(MealFamily mealFamily){
		this.sessionFactory
		.getCurrentSession()
		.delete(mealFamily);
	}
}
